﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace admin
{
    /// <summary>
    /// Класс формы для регистрации
    /// </summary>
    public partial class registration : Window
    {
        // Данные для заселения нового клиента
        private String szName;
        private String szSurname;
        private String szSecondName;
        private int roomId;
        private String checkIn;
        private String checkOut;

        public registration(int roomId)
        {
            InitializeComponent();
            this.roomId = roomId;
            regLbl.Content = regLbl.Content + " (комната №" + Convert.ToString(roomId) + ")";
        }

        private bool RegisterNewClient()
        {
            return false;
        }

        /// <summary>
        /// Процедура регистрации нового клиента
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdRegister_Click(object sender, RoutedEventArgs e)
        {
            szName = txtName.Text;
            szSurname = txtSurname.Text;
            szSecondName = txtPatronymic.Text;

            // сделать проверку дат

            if (szName == "" || szSurname == "" || szSecondName == ""||
                checkIn == "" || checkOut == "")
            {
                MessageBox.Show("Необходимо заполнить все поля!");
                return;
            }

            if(Convert.ToDateTime(checkIn) >= Convert.ToDateTime(checkOut)){
                MessageBox.Show("Ошибка заполнения дат!");
                return;
            }

            // send sql request
            App.MyBase.AddNewClient(szName, szSecondName, szSurname, Convert.ToDateTime(checkIn),
                                Convert.ToDateTime(checkOut), roomId);

            MessageBox.Show("Клиент успешно зарегистрирован!");
        }

        private void cmdClose_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void dateCheckIn_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            checkIn = wgtCheckIn.Text;
        }

        private void wgtCheckOut_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            checkOut = wgtCheckOut.Text;
        }
    }
}
